﻿function ClientUploadImageUrlFromAddNews(NewsId) {
    Url = Portal.CMS.AddNews.GetUpdateImageUrl(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function ClientSaveNews(GroupNewsId, NewsId) {
    Subject = document.getElementById("txtSubject").value;
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;

    if (FCKeditorAPI == null) {
        alert(Portal.CMS.UpdateNews.GetLoadDataMsg().value);
        return;
    }

    var instanceName = "ctl04";
    var oEditor = FCKeditorAPI.GetInstance(instanceName);

    if (oEditor == null) {
        alert(Portal.CMS.UpdateNews.GetLoadDataMsg().value);
        return;
    }
    ShortContent = oEditor.GetXHTML(true);

    instanceName = "ctl05";
    oEditor = FCKeditorAPI.GetInstance(instanceName);
    if (oEditor == null) {
        alert(Portal.CMS.UpdateNews.GetLoadDataMsg().value);
        return;
    }
    bodyText = oEditor.GetXHTML(true);
    SearchKeyword = document.getElementById("txtSearchKeyword").value;
    ImageUrl = document.getElementById("txtImageUrl").value;
    Source = document.getElementById("txtSource").value;
    EntryDate = document.getElementById("txtEntryDate").value;

    value = Portal.CMS.UpdateNews.ServerSideNews(language, NewsId, Subject, ImageUrl, ShortContent, bodyText, SearchKeyword, Source, EntryDate).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    alert(value)
    //window.close();
}

function RunFilter(GroupNewsId) {
    WorkflowStatusIndex = document.getElementById("divSelectWorkflowStatus").selectedIndex;
    WorkflowStatus = "";
    if (WorkflowStatusIndex != -1) {
        WorkflowStatus = document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    }
    GroupNewsItemId = document.getElementById("drpSelectGroupNews").options[document.getElementById("drpSelectGroupNews").selectedIndex].value;
    PageIndex = 0;
    if (document.getElementById("divSelectPage") != null) {
        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    }
    value = Portal.CMS.SearchNews.GetHtml(GroupNewsId, GroupNewsItemId, WorkflowStatus, PageIndex).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    document.getElementById("divNewsContent").innerHTML = value;
}

function RunFilterStdAlone() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.SearchNews.GetProcessingMsg().value;
    setTimeout("RealRunFilterStdAlone()", 10);
}


function RealRunFilterStdAlone() {
    WorkflowStatusIndex = document.getElementById("divSelectWorkflowStatus").selectedIndex;
    WorkflowStatus = "";
    if (WorkflowStatusIndex != -1) {
        WorkflowStatus = document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    }
    GroupNewsItemId = document.getElementById("txtGroupNewsItemId").value;
    GroupNewsId = document.getElementById("txtGroupNewsId").value;
    PageIndex = 0;
    if (document.getElementById("divSelectPage") != null) {
        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    }
    value = Portal.CMS.SearchNews.GetHtml(GroupNewsId, GroupNewsItemId, WorkflowStatus, PageIndex).value;
    if (value.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(value);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divNewsContent").innerHTML = value;
}


function ClientDeleteNews(GroupNewsId, NewsId) {
    value = Portal.CMS.SearchNews.CheckAllowDelete(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    if (confirm(Portal.CMS.SearchNews.GetConfirmMsg().value) == false) {
        return;
    }
    value = Portal.CMS.SearchNews.ServerSideDeleteNews(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    alert(Portal.CMS.SearchNews.GetDeleteOkMsg().value);
    WorkflowStatusIndex = document.getElementById("divSelectWorkflowStatus").selectedIndex;
    WorkflowStatus = document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    PageIndex = 0;
    if (document.getElementById("divSelectPage") != null) {
        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    }
    GroupNewsItemId = document.getElementById("drpSelectGroupNews").options[document.getElementById("drpSelectGroupNews").selectedIndex].value;
    value = Portal.CMS.SearchNews.GetHtml(GroupNewsId, GroupNewsItemId, WorkflowStatus, PageIndex).value;
    document.getElementById("divNewsContent").innerHTML = value;
}



function ClientDeleteStdAloneNews(GroupNewsId, GroupNewsItemId, NewsId) {
    value = Portal.CMS.SearchNews.CheckAllowDelete(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    if (confirm(Portal.CMS.SearchNews.GetConfirmMsg().value) == false) {
        return;
    }
    value = Portal.CMS.SearchNews.ServerSideDeleteNews(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    alert(Portal.CMS.SearchNews.GetDeleteOkMsg().value);
    WorkflowStatusIndex = document.getElementById("divSelectWorkflowStatus").selectedIndex;
    WorkflowStatus = document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    PageIndex = 0;
    if (document.getElementById("divSelectPage") != null) {
        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    }
    value = Portal.CMS.SearchNews.GetHtml(GroupNewsId, GroupNewsItemId, WorkflowStatus, PageIndex).value;
    document.getElementById("divNewsContent").innerHTML = value;
}



function ClientDeleteSearchNews(GroupNewsId, GroupNewsItemId, NewsId) {
    value = Portal.CMS.SearchNews.CheckAllowDelete(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    if (confirm(Portal.CMS.SearchNews.GetConfirmMsg().value) == false) {
        return;
    }
    value = Portal.CMS.SearchNews.ServerSideDeleteNews(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    alert(Portal.CMS.SearchNews.GetDeleteOkMsg().value);
    SearchNewsJumpPage();
}


function ShowUpdateNewsForm(GroupNewsId, NewsId) {
    Url = Portal.CMS.SearchNews.GetUpdateNewsUrl(GroupNewsId, NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //    WorkflowStatusIndex=document.getElementById("divSelectWorkflowStatus").selectedIndex;
    //    WorkflowStatus=document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    //    PageIndex = 0;
    //    if (document.getElementById("divSelectPage") != null) {
    //        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    //    }
    //    GroupNewsItemId=document.getElementById("drpSelectGroupNews").options[document.getElementById("drpSelectGroupNews").selectedIndex].value;
    //    value=Portal.CMS.SearchNews.GetHtml(GroupNewsId,GroupNewsItemId,WorkflowStatus,PageIndex).value;
    //    if(value.indexOf("ERROR")==-1)
    //    {
    //        document.getElementById("divNewsContent").innerHTML=value;
    //    }
    //    else
    //    {
    //        alert(value);
    //    }
}


function ShowUpdateSearchNewsForm(GroupNewsId, GroupNewsItemId, NewsId) {
    Url = Portal.CMS.SearchNews.GetUpdateNewsUrl(GroupNewsId, NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    SearchNewsJumpPage();
}


function ShowUpdateStdAloneNewsForm(GroupNewsId, GroupNewsItemId, NewsId) {
    Url = Portal.CMS.SearchNews.GetUpdateNewsUrl(GroupNewsId, NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
    //    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //    WorkflowStatusIndex=document.getElementById("divSelectWorkflowStatus").selectedIndex;
    //    WorkflowStatus=document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    //    PageIndex = 0;
    //    if (document.getElementById("divSelectPage") != null) {
    //        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    //    }
    //    value=Portal.CMS.SearchNews.GetHtml(GroupNewsId,GroupNewsItemId,WorkflowStatus,PageIndex).value;
    //    if(value.indexOf("ERROR")==-1)
    //    {
    //        document.getElementById("divNewsContent").innerHTML=value;
    //    }
    //    else
    //    {
    //        alert(value);
    //    }
}


function DetectHtmlBody(NewsId) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue = Portal.CMS.UpdateNews.GetSubject(language, NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("txtSubject").value = retValue;

    //shortcontent
    var instanceName = "ctl04";
    var oEditor = FCKeditorAPI.GetInstance(instanceName);
    retValue = Portal.CMS.UpdateNews.GetShortContent(language, NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    oEditor.SetHTML(retValue);


    //body
    instanceName = "ctl05";
    oEditor = FCKeditorAPI.GetInstance(instanceName);
    retValue = Portal.CMS.UpdateNews.GetBody(language, NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    oEditor.SetHTML(retValue);
}

function PublishingNews(NewsId) {
    retValue = Portal.CMS.SearchNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.SearchNews.GetConfirmPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.SearchNews.ServerSidePublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function UnPublishingNews(NewsId) {
    retValue = Portal.CMS.SearchNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.SearchNews.GetConfirmUnPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.SearchNews.ServerSideUnPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function PublishingStdAloneNews(NewsId) {
    retValue = Portal.CMS.SearchNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.SearchNews.GetConfirmPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.SearchNews.ServerSidePublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}


function UnPublishingStdAloneNews(NewsId) {
    retValue = Portal.CMS.SearchNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.SearchNews.GetConfirmUnPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.SearchNews.ServerSideUnPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}







function PublishingSearchNews(NewsId) {
    retValue = Portal.CMS.SearchNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.SearchNews.GetConfirmPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.SearchNews.ServerSidePublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}


function UnPublishingSearchNews(NewsId) {
    retValue = Portal.CMS.SearchNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.SearchNews.GetConfirmUnPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.SearchNews.ServerSideUnPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}



function PermissionStdAloneNews(NewsId) {
    Url = Portal.CMS.SearchNews.GetShowFormSetPermission(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');

}


function PermissionNews(NewsId) {
    Url = Portal.CMS.SearchNews.GetShowFormSetPermission(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');

}

function ClientUploadImageUrl(NewsId) {
    Url = Portal.CMS.SearchNews.GetUpdateImageUrl(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function ClientUploadImageUrlForSearchNews(NewsId) {
    Url = Portal.CMS.SearchNews.GetUpdateImageUrl(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function SearchNewsJumpPage() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.SearchNews.GetSearchProcessingMsg().value;
    setTimeout("RealSearchNewsJumpPage()", 10);
}

function RealSearchNewsJumpPage() {
    WorkflowStatusIndex = document.getElementById("drpSelectWorkflowStatus").selectedIndex;
    Keyword = document.getElementById("txtSearchKeyword").value;
    fromDate = document.getElementById("txtFromDate").value;
    toDate = document.getElementById("txtToDate").value;
    belongSiteIndex = document.getElementById("drpSelectSite").selectedIndex;
    belongSite = document.getElementById("drpSelectSite").options[belongSiteIndex].value;
    GroupNewsItemId = document.getElementById("drpSelectGroupNewsItem").options[document.getElementById("drpSelectGroupNewsItem").selectedIndex].value;
    Source = document.getElementById("txtSource").value;
    PageIndex = 0;
    if (document.getElementById("divSelectSearchNewsPage") != null) {
        PageIndex = document.getElementById("divSelectSearchNewsPage").selectedIndex;
    }

    retValue = Portal.CMS.SearchNews.GetHtml(belongSite, Keyword, fromDate, toDate, WorkflowStatusIndex, GroupNewsItemId, Source, PageIndex).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divSearchNewsContent").innerHTML = retValue;
}

function FilterFunc() {
    LoadGroupNewsItem();
}

function LoadGroupNewsItem() {
    belongSite = document.getElementById("drpSelectSite").options[document.getElementById("drpSelectSite").selectedIndex].value;
    retValue = Portal.CMS.SearchNews.ServerSideGetGroupNewsItem(belongSite).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divSelectGroupNewsItem").innerHTML = retValue;
}

function ClientSetShowOnTop(NewsId) {
    retValue = Portal.CMS.SearchNews.ServerSideSetShowOnTop(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}


function ClientSyncNews(NewsId) {
    if (confirm(Portal.CMS.SearchNews.GetConfirmSyncAllMsg().value) == false) {
        return;
    }
    document.getElementById("divProcessing").innerHTML = Portal.CMS.SearchNews.GetSyncProcessing().value;
    setTimeout("RealClientSyncNews('" + NewsId + "')", 10);
}

function RealClientSyncNews(NewsId) {
    retValue = Portal.CMS.SearchNews.ServerSideSyncToServer(NewsId).value;
    document.getElementById("divProcessing").innerHTML = "";
    alert(retValue);
}

function ClientMoveItemNews(belongSite, GroupNewsItemId, NewsId) {
    url = Portal.CMS.SearchNews.GetMoveNewsUrl(NewsId).value;
    if (url.indexOf("ERROR") != -1) {
        alert(url);
        return;
    }
    //window.showModalDialog(url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(url, '_blank');
}



function ClientExecuteMoveNews(NewsId) {
    if (confirm(Portal.CMS.MoveNews.GetConfirmMoveMsg().value) == false) {
        return;
    }
    document.getElementById("divProcessing").innerHTML = Portal.CMS.MoveNews.GetProcessingMove().value;
    setTimeout("RealClientExecuteMoveNews('" + NewsId + "')", 10);
}

function RealClientExecuteMoveNews(NewsId) {

    MoveToGroupNewsItemId = document.getElementById("drpSelectGroupNewsItem").options[document.getElementById("drpSelectGroupNewsItem").selectedIndex].value;
    retValue = Portal.CMS.MoveNews.ServerSideMoveNews(NewsId, MoveToGroupNewsItemId).value;
    document.getElementById("divProcessing").innerHTML = "";
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
    window.close();
}

function ClientUploadDocumentContent(belongSite, NewsId) {
    url = Portal.CMS.SearchNews.GetUploadDocumentContentUrl(belongSite, NewsId).value;
    if (url.indexOf("ERROR") != -1) {
        alert(url);
        return;
    }
    window.open(url, '_blank');
}

function ShowNewsHistory(NewsId) {
    Url = Portal.CMS.SearchNews.GetLogUrl(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}

function ClientDetectGroupNewsItem() {
    GroupNewsId = document.getElementById("drpSelectGroupNews").options[document.getElementById("drpSelectGroupNews").selectedIndex].value;
    retValue = Portal.CMS.MoveNews.ServerSideDetectGroupNewsItem(GroupNewsId).value;
    document.getElementById("divSelectGroupNewsItems").innerHTML = retValue;
}



function ClientShowRelationNewsFormSearchNews(NewsId) {
    url = Portal.CMS.SearchNews.GetRelationFormUrl(NewsId).value;
    if (url.indexOf("ERROR") != -1) {
        alert(url);
        return;
    }
    window.open(url, '_blank');
}